<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<input type="button" value="Add Script" onclick="addScript()">
<script type="text/javascript">
function loadScriptString(code){
	var script = document.createElement("script");
	script.type = "text/javascript";
	try {
		script.appendChild(document.createTextNode(code));
	} catch (ex){
		script.text = code;
	}
	document.body.appendChild(script);
}
function addScript(){
	loadScriptString("function sayHi(){alert('hi');}");
	sayHi();
}
</script>
</body>
</html>
